const service = require('../service/user.service')
const { getAvatarByUserid } = require('../service/file.service')
const fs = require('fs')

class UserController {
  async create(ctx, next) {
    const user = ctx.request.body
    const results = await service.create(user)
    ctx.body = results
  }
  async getAvatar(ctx, next) {
    const { userId } = ctx.params
    const results = await getAvatarByUserid(userId)
    const userAvatar = results[0]
    ctx.body = fs.createReadStream(`./uploads/avatar/${userAvatar.filename}`)
    ctx.response.set('content-type', userAvatar.mimetype)
  }
}
module.exports = new UserController()
